package STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Model;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID;

import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Book;
import STUDENT.LETRUNGHIEU.GENERICS_EXERCISES.objects.Reader;
import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Entity.BookManager;
import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Entity.Books;
import STUDENT.TranNamAnh.OOPs.baitapmang.quanlymuonsach.Entity.Guests;

public class Models {
	BookManager managerObj = new BookManager();

	public void addBooḳ̣̣(Books bookObj) {
		managerObj.getBookList().add(bookObj);
	}

	public void addGuest(Guests guestObj) {
		managerObj.getGuestList().add(guestObj);
	}

	public void showBook() {
		Iterator<Books> itr = managerObj.getBookList().iterator();

		while (itr.hasNext()) {
			Books bookObj = (Books) itr.next();
			System.out.println(managerObj);
		}
	}

	public void showGuest() {
		Iterator<Guests> itr = managerObj.getGuestList().iterator();

		while (itr.hasNext()) {
			Guests guestObj = (Guests) itr.next();
			System.out.println(managerObj);
		}

	}

	public void borrowBook(String bookName, String guestName) {
		Iterator<Books> itr = managerObj.getBookList().iterator();
		Iterator<Guests> itr2 = managerObj.getGuestList().iterator();

		String bookNameBr = null, guestNameBr = null;

		while (itr.hasNext()) {
			if (bookName.equals(itr.next().getBookName()))
				bookNameBr = bookName;
		}
		while (itr2.hasNext()) {
			if (guestName.equals(itr2.next().getGuestName()))
				guestNameBr = guestName;
		}
		managerObj.getMap().put(bookNameBr, guestNameBr);
	}
	
	public void showBorrow(){
		Set<Entry<String, String>> entries = managerObj.getMap().entrySet();
	    for(Entry<String, String> entry :entries){
	    	System.out.println("Book: " + entry.getKey() + " - Guest: " + entry.getValue());
	    }
	}
}
